package com.ruoyi.front_desk.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.front_desk.FrontdeskRepresentativePerformance.domain.FrontdeskRepresentativePerformance;
import com.ruoyi.front_desk.FrontdeskRepresentativePerformance.mapper.FrontdeskRepresentativePerformanceMapper;
import com.ruoyi.front_desk.FrontdeskRepresentativePerformance.service.FrontdeskRepresentativeService;
import com.ruoyi.management_controller.RepresentativePerformance.domain.RepresentativePerformance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @author 刘奥旸
 * @version 1.0
 */
@RestController
public class FrontdeskRepresentativeController extends BaseController {
    @Autowired
    FrontdeskRepresentativeService frontdeskRepresentativeService;
    @Autowired
    FrontdeskRepresentativePerformanceMapper frontdeskRepresentativePerformanceMapper;
    @PostMapping(value = "/FrontdeskRepresentative/add")
    public AjaxResult addPerformance(@RequestBody RepresentativePerformance performance) {
        try {
            frontdeskRepresentativePerformanceMapper.insertFrontdeskRepresentativePerformance(performance);
            return AjaxResult.success();
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }

    @GetMapping(value = "/FrontdeskRepresentative/list")
    public TableDataInfo findById(@RequestParam(required = false)  String date,@RequestParam Integer id) {
        startPage();
        if(StringUtils.isEmpty(date)){
            Calendar cal = Calendar.getInstance();  // 获取当前时间的Calendar实例
            int year = cal.get(Calendar.YEAR);
            date=String.valueOf(year);
        }
        List<RepresentativePerformance> frontdeskRepresentativePerformances = frontdeskRepresentativeService.selectById(date,id);
        return getDataTable(frontdeskRepresentativePerformances);

    }

    @GetMapping(value = "/FrontdeskRepresentative/findByDate")
    public TableDataInfo findByDate(@RequestParam String date,int id) {
        startPage();

        List<RepresentativePerformance> frontdeskRepresentativePerformances = frontdeskRepresentativeService.selectByDate(date,id);
        return getDataTable(frontdeskRepresentativePerformances);

    }



}
